/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tasks.ui.architecture;

import domain.LayerDTO;
import java.util.LinkedList;
import java.util.Map;
import javax.swing.AbstractListModel;

/**
 *
 * @author David
 */
public class LayerListModel extends AbstractListModel {

    private LinkedList<LayerDTO> layers = new LinkedList<LayerDTO>();
    
    public LayerListModel(){
        
    }

    public LayerListModel(Map<String, LayerDTO> layersMap) {
        layers.addAll(layersMap.values());
    }
    
    public void setLayers(Map<String, LayerDTO> layersMap){
        layers.addAll(layersMap.values());
    }

    @Override
    public int getSize() {
        return layers.size();
    }

    @Override
    public Object getElementAt(int index) {
        return this.layers.get(index).getNumber() + ": " + this.layers.get(index).getName();
    }

    public String getLayerAt(int index) {
        return layers.get(index).getName();
    }
    
    public int getIndexOfLayer(String layer){
        if(layer != null){
            for(LayerDTO layerInList : layers){
                if(layerInList.getName().equals(layer)){
                    return layers.indexOf(layerInList);
                }
            }
        }
        return -1;
    }
}
